package com.ctshk.sapp.air.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.air.dto.AirFlightDataDto;
import com.ctshk.rpc.air.req.AirFlightAddReq;
import com.ctshk.rpc.air.req.AirFlightListReq;
import com.ctshk.rpc.air.req.AirFlightQueryReq;
import com.ctshk.rpc.air.req.AirFlightUpdateReq;
import com.ctshk.rpc.air.service.IAirFlightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 航班表 前端控制器
 * </p>
 *
 * @author lihang
 * @since 2021-03-04
 */
@Api(value = "航班管理",tags = "航班管理")
@RestController
@RequestMapping("/air-flight")
public class AirFlightController extends BaseController {


    @DubboReference
    private IAirFlightService iAirFlightService;

    /**
     * 新增航班信息
     */
    @ApiOperation(value = "新增航班信息", notes = "新增航班信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增航班信息", operDesc = "新增航班信息")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AirFlightAddReq req) {
        return  iAirFlightService.add(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询航班详情", notes = "查询航班详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询航班详情", operDesc = "查询航班详情")
    @PostMapping("/query")
    public Result<AirFlightDataDto> query(@RequestBody @Valid AirFlightQueryReq req){
        return  iAirFlightService.query(req);
    }

    @ApiOperation(value = "查询航班信息列表", notes = "查询航班信息列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询航班信息列表", operDesc = "查询航班信息列表")
    @PostMapping("/list")
    public Result<PageResponse<AirFlightDataDto>> list(@RequestBody AirFlightListReq req){
        PageResponse<AirFlightDataDto> list = iAirFlightService.list(req);
        return  Result.success(list);
    }

    @ApiOperation(value = "修改航班信息", notes = "修改航班信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改航班信息", operDesc = "修改航班信息")
    @PostMapping("/edit")
    public Result edit(@RequestBody AirFlightUpdateReq req){
        return  iAirFlightService.edit(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改航班状态", notes = "修改航班状态")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改航班状态", operDesc = "修改航班状态")
    @PostMapping("/edit/status")
    public Result editStatus(@RequestBody AirFlightUpdateReq req){
        return  iAirFlightService.editStatus(req,getCurrentUser(getRequest()));
    }
}
